<?php
function site_config_validate() {
    $result['error'] = array();
    $result['config'] = array();
    
    $site_name = stripslashes(trim($_POST['site_name']));
    if (strlen($site_name) == 0) {
        $result['error']['site_name'] = '请输入站点名称';
    }
    $result['config']['site_name'] = $site_name;
    
    $copyright = stripslashes(trim($_POST['copyright']));
    $result['config']['copyright'] = $copyright;
    
    $tech_support = stripslashes(trim($_POST['tech_support']));
    $result['config']['tech_support'] = $tech_support;
    
    $icp = stripslashes(trim($_POST['icp']));
    $result['config']['icp'] = $icp;
    
    $client_address = stripslashes(trim($_POST['client_address']));
    $result['config']['client_address'] = $client_address;
		
		$press = stripslashes(trim($_POST['press']));
    $result['config']['press'] = $press;
		
		$index_redirect = stripslashes(trim($_POST['index_redirect']));
    $result['config']['index_redirect'] = $index_redirect;
    
    return $result;
}

function site_config_getConfig() {
    $config = array();
    
    $conn = getDBConnection();
    $result = $conn->query('select meta_key, meta_value from t_site_config');
    while ($row = &$result->fetchRow()) {
        $config[$row[0]] = $row[1];
    }
    $result->free();
    $conn->disconnect();
    
    return $config;
}
function site_config_update($config) {
    $conn = getDBConnection();
		
    foreach ($config as $meta_key=>$meta_value) {
        $conn->query("update t_site_config set meta_value=? where meta_key=?", array($meta_value, $meta_key));
    }
    
    $conn->disconnect();
}


?>